package com.dubito.encrypt.sha;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.Security;

/**
 * @author liliang
 * @description:
 * @date 2018/5/17.
 */
public class RipeMd160 {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String s = "RipeMD160第三方摘要算法测试";
        byte[] r = pipeMD160(s.getBytes("UTF-8"));
        System.out.println(r.length);
        System.out.println(String.format("%032x",new BigInteger(1,r)));
    }

    public static byte[] pipeMD160(byte[] input) {
        Security.addProvider(new BouncyCastleProvider());
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("RipeMD160");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        md.update(input);
        return md.digest();
    }

}
